package com.bianmaba;

import com.bianmaba.services.datacollection.quartiz.QuartzTaskManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @program: samples
 * @description:
 * @author: Chenjiabin
 * @create: 2019/9/9 15:48
 **/
@SpringBootApplication
//目前没发现这个注解有啥用，不注解也可以正常使用系统缓存及hibernate二级缓存，感觉没有开启功能而只是配置功能
@EnableCaching()
public class QuartzApplication {

    public static void main(String[] args) {
        SpringApplication.run(QuartzApplication.class, args);
    }

    @Autowired
    private QuartzTaskManager executor;

    //此处是启动任务执行计划的地方
    @Bean
    public String createScedules() {
//        //----------------------启动远程任务-----
//        JobDataMap jobDataMap = new JobDataMap();
//        jobDataMap.put("description", "执行一次性任务1");
//        executor.executeOnece(DefaultJob.class, "DoCreateTableJobOnece", "test", jobDataMap);
//
//        jobDataMap.put("description", "指定时间点执行一次性任务1");
//        executor.executeOnece(DefaultJob.class, "DoCreateTableJobOnece", "test", jobDataMap, 5);
//
//        jobDataMap = new JobDataMap();
//        jobDataMap.put("description", "使用自定义执行器执行Cron表达式任务(1秒执行一次)-01");
//        executor.submitCronSchedule(DefaultJob.class, "DoCreateTableJob", null, "0/1 * * * * ?", jobDataMap);
//
        return "createScedule";
    }

    @Bean
    @ConditionalOnMissingBean(ExecutorService.class)
    public ExecutorService executorService() {
        ExecutorService executorService = Executors.newCachedThreadPool();
        return executorService;
    }
}